/**
 * @created by kongqf on 2019-12-17 13:54:46
 * @updated by
 * @description wfdemo
 */
/* eslint no-undef:0 */
/* eslint new-cap:0 */

define([
  './libs/mxgraph/libs/init.js',
  './libs/mxgraph/mxClient.js',
  './pages/workflow/studio/nwflist/jWorkflow/jobFlowGraph.css',
  './libs/mxgraph/libs/sanitizer.min.js',
  './libs/mxgraph/libs/editorUi.js',
  './libs/mxgraph/libs/editor.js',
  './libs/mxgraph/libs/sidebar.js',
  './libs/mxgraph/libs/graph.js',
  './libs/mxgraph/libs/format.js',
  './libs/mxgraph/libs/shapes.js',
  './libs/mxgraph/libs/actions.js',
  './libs/mxgraph/libs/menus.js',
  './libs/mxgraph/libs/toolbar.js',
  './libs/mxgraph/libs/dialogs.js',
  './custom/widgets/js/YuWorkflow.js'
], function (require, exports) {
  /**
   * 页面加载完成时触发
   * @param hashCode 路由ID
   * @param data 传递数据对象
   * @param cite 页面站点信息
   */
  exports.ready = function (hashCode, data, cite) {
    var size = yufp.frame.size();
    yufp.custom.vue({
      el: cite.el,
      data: function () {
        return {
          height: 390,
          value2: 100,
          viewScale: '100%',
          graphData: null,
          formItems: {},
          showSidebar: true,
          showFormatbar: true,
          workflowData: data,
          formatType: '',
          tmpCell: null,
          locked: true, // 是否预览模式，会自动屏蔽界面上输入操作
          returnBackFuncId: '',
          returnBackRootId: '',
        };
      },
      mounted: function () {
        this.returnBackFuncId = data.returnBackFuncId;
        this.returnBackRootId = data.returnBackRootId;
      },
      methods: {
        // 初始化左侧示例图标
        initGraph: function () {
          if (this.locked) {
            this.hideSidebarFn();
            this.hideFormatbarFn();
          }
          this.initData();
        },
        // 初始化绑定数据
        initData: function () {
          var _this = this;// 获取流程图
          yufp.service.request({
            url: backend.workflowService + '/api/nwfflow/flow',
            data: { flowId: data.flowId },
            callback: function (code, msg, response) {
              _this.graphData = response.data.flowContent;
              _this.graphData && (_this.workflowData = _this.$refs.refWorkflow.loadXML(_this.graphData));
              _this.$nextTick(function () {
                var cells = _this.$refs.refWorkflow.graph.getModel().cells;
              });
            }
          });
        },
        // 节点单击事件
        cellclickFn: function (cell) {
        },
        // 隐藏左侧面板
        hideSidebarFn: function () {
          this.$refs.refWorkflow.hideSidebar(this.showSidebar = !this.showSidebar);
        },
        // 隐藏右侧面板
        hideFormatbarFn: function () {
          this.$refs.refWorkflow.hideFormatbar(this.showFormatbar = !this.showFormatbar);
        }
      }
    });
  };

  /**
   * 页面传递消息处理
   * @param type 消息类型
   * @param message 消息内容
   */
  exports.onmessage = function (type, message, cite, vm) {
    if (type === 'active-tab') {
      vm.$refs.refWorkflow.hiddenOutlineWindow(false);
    }
    if (type === 'active-tab-self') {
      vm.$refs.refWorkflow.hiddenOutlineWindow(true);
    }
  };

  /**
   * 页面销毁时触发destroy方法
   * @param id 路由ID
   * @param cite 页面站点信息
   */
  exports.destroy = function (id, cite) {
  };
});